<?php
namespace app\admin\controller;
use app\admin\controller\Basic;
use think\Db;
class System extends Basic{
    public function _initialize(){
        parent::_initialize();
        $this->assign('left','system');
        $this->assign('act','system');
        $tplpath = ROOT_PATH.'/run_theme/'.get_langpath('admin',$this->lid);
        $this->assign('domain',request()->domain());
        $this->assign('theme_path',get_tpl($tplpath));
    }
    public function index(){
    	if(isajax()){
    		checktoken();
            $arr = require(EXTEND_PATH.'field'.EXT);
	        foreach($_POST as $k=>$v){
	        	if(in_array($k,$arr['sysun'])){
	        		$cfg[$k] = $v;
	        		unset($_POST[$k]);
	        	}
	        	$safe = $this->safe;
	        	$data[$k] = $safe->encode($v);
	        }
	        replace_arr(CONFIG_PATH,$cfg);
	        Db::name('config')->where('id',$this->lid)->update(['content'=>json_encode($data)]);
	        exit(json_encode(['status'=>1,'msg'=>'更新成功']));
    	}
        $this->assign('left','company');
        return $this->fetch();
    }
}